﻿#include <iostream>
#include <vector>
#include <map>
#include "Date.h"
using namespace std;



//struct S
//{
//	int x;
//	int y;
//};
//
//int main()
//{
	// C++98 {} -> 初始化数组和结构体
	//int array1[] = { 1,2,3,4,5 };
	//int array2[5] = { 0 };
	//S object = { 1, 2 };

	//// C++11 {}
	//int a1 = { 1 };
	//int a2 = 1;

	// 一切对象皆可初始化
	//Date d1 = { 2024, 12, 9 };

	// 获取构造的临时对象
	//const Date& d2 = { 2024, 12, 9 };

	/*vector<Date> v;
	v.push_back({ 2024, 12, 9 });*/

	///* mylist中只存储了两个指针，x64环境一个指针8字节 */
	//std::initializer_list<int> mylist;
	//mylist = { 10, 20, 30, 40 };
	//cout << sizeof(mylist) << endl;

//	/* 直接构造 */
//	vector<int> v1({ 1,2,3,4,5 });
//	/* 构造临时对象+拷贝构造 -> 优化为直接构造*/
//	vector<int> v2 = { 1,2,3,4,5 };
//	/* pair构造+{}列表初始化 */
//	map<string, string> dict{ {"string", "字符串"}, {"left", "左边"} };
//
//	return 0;
//}

void f(int& x)
{
	std::cout << "左值引用重载 f(" << x << ")\n";
} 

void f(const int& x)
{
	std::cout << "到 const 的左值引用重载 f(" << x << ")\n";
} 

void f(int&& x)
{
	std::cout << "右值引用重载 f(" << x << ")\n";
}

int main()
{
	int a = 0;
	int& r1 = a;			// 左值引用
	const int& r2 = a;	    // const引用左值
	const int& r3 = 1 + 1;  // const引用右值
	int&& r4 = 1 + 1;		// 右值引用
	f(r1); f(r2); f(r3); f(r4), f(1 + 1);

	/*int a = 0;
	int& b = a;
	int&& c = 1 + 1;
	cout << &b << endl;
	cout << &c << endl;*/

	//// 常见的左值
	//// 左值：可以取地址
	//// 以下的p、b、c、*p、s、s[0]就是常见的左值
	//int* p = new int(0);
	//int b = 1;
	//const int c = b;
	//*p = 10;
	//string s("111111");
	//s[0] = 'x';


	//// 常见的左值
	//// 左值：可以取地址
	//// 以下的p、b、c、*p、s、s[0]就是常见的左值
	//int* p = new int(0);
	//int b = 1;
	//const int c = b;
	//*p = 10;
	//string s("111111");
	//s[0] = 'x';

	//// 右值：不能取地址
	//double x = 1.1, y = 2.2;
	//// 以下⼏个10、x + y、fmin(x, y)、string("11111")都是常⻅的右值
	//10;
	//x + y;
	//fmin(x, y);
	//string("11111");


	//// 延长生命周期
	//const int& x = 1 + 1;
	//int&& y = 1 + 1;
	//// cout << x++ << endl; // err
	//cout << ++y << endl;

	return 0;
}

class Solution {
public:
	// 这⾥的传值返回拷贝代价就太⼤了
	vector<vector<int>> generate(int numRows) {
		vector<vector<int>> vv(numRows);
		for (int i = 0; i < numRows; ++i)
		{
			vv[i].resize(i + 1, 1);
		} 
		for (int i = 2; i < numRows; ++i)
		{
			for (int j = 1; j < i; ++j)
			{
				vv[i][j] = vv[i - 1][j] + vv[i - 1][j - 1];
			}
		} 
		return vv;
	}
};